﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DBEntity;
using System.Data;
using Dapper;
using System.Data.SqlClient;
using DBEntity.Models;
using MySql.Data.MySqlClient;

namespace DBClass
{
    public class DBHelper
    {
        private static string connectionString;
        static IDbConnection connection;

        public DBHelper()
        {

        }
        public DBHelper(string conn)
        {
            connectionString = conn;
            connection = new MySqlConnection(connectionString);
        }

        /// <summary>
        /// 获取未匹配计划数据
        /// </summary>
        /// <returns></returns>
        public static DataTable GetPlan()
        {
            DataTable data = new DataTable();
            string sql = @"select * from AUDIT_PER";
            var result = connection.ExecuteReader(sql);
            data.Load(result);
            return data;           
        }

        /// <summary>
        /// 获取停机报告
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<DBEntity.Models.ACT_SHUTDOWN> GetShutdown()
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<DBEntity.Models.ACT_SHUTDOWN>("select * from ACT_SHUTDOWN order by RecordTime desc");
                return result;
            }
        }

        /// <summary>
        /// 获取停机报告
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<DBEntity.Models.ACT_SHUTDOWN> GetShutdown(string startTime, string endTime)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<DBEntity.Models.ACT_SHUTDOWN>("select * from ACT_SHUTDOWN where DownStartTime between @startTime and @endTime order by RecordTime desc"
                    , new { @startTime = startTime, @endTime = endTime });
                return result;
            }
        }

        /// <summary>
        /// 根据ID获取停机报告
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static IEnumerable<DBEntity.Models.ACT_SHUTDOWN> GetShutdown(string id)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<DBEntity.Models.ACT_SHUTDOWN>("select * from ACT_SHUTDOWN where ID=@id", new { @id = id });
                return result;
            }
        }

        /// <summary>
        /// 删除停机报告
        /// </summary>
        /// <param name="ids">要删除的id，格式id1,id2,...</param>
        /// <returns></returns>
        public static bool DeleteShutdown(List<int> ids)
        {
            int result = 0;
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                foreach (int id in ids)
                {
                    result += connection.Execute("delete  from ACT_SHUTDOWN where ID = @id ", new { @id = id });

                }
                if (result > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

        /// <summary>
        /// 新增停机报告
        /// </summary>
        /// <param name="shutdown">停机报告</param>
        /// <returns></returns>
        public static int InsertShutdown(ACT_SHUTDOWN shutdown)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<int>("insert into  ACT_SHUTDOWN(LineID, DownStartTime, DownEndTime, DownTimeDuration,DownTimeReason) values (@LineID, @DownStartTime, @DownEndTime, @DownTimeDuration,@DownTimeReason);SELECT @@IDENTITY;", shutdown);
                return result.FirstOrDefault();
            }
        }
        /// <summary>
        /// 更新停机报告
        /// </summary>
        /// <param name="shutdown">停机报告</param>
        /// <returns></returns>
        public static bool UpdateShutdown(ACT_SHUTDOWN shutdown)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                int result = connection.Execute("update ACT_SHUTDOWN set LineID=@LineID, DownStartTime=@DownStartTime, DownEndTime=@DownEndTime, DownTimeDuration=@DownTimeDuration,DownTimeReason=@DownTimeReason where ID=@ID", shutdown);
                if (result > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

        #region dw 巡检任务 

        /// <summary>
        /// 获取巡检任务
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<DBEntity.Models.AUDIT_TASK> GetAuditTask(string area)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<DBEntity.Models.AUDIT_TASK>("select * from AUDIT_TASK where AREA_NAME = @area"
                    , new { @area = area });
                return result;
            }
        }

        /// <summary>
        /// 获取巡检任务
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<DBEntity.Models.AUDIT_TASK> GetAuditTaskById(string id)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<DBEntity.Models.AUDIT_TASK>("select * from AUDIT_TASK where TASK_ID = @TASK_ID"
                    , new { @TASK_ID = id });
                return result;
            }
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="task">任务</param>
        /// <returns></returns>
        public static int InsertAuditTask(AUDIT_TASK task)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<int>("insert into  AUDIT_TASK(TASK_ID, TASK_NAME, AREA_NAME,STATION_NAME,TASK_CODE) values (@TASK_ID, @TASK_NAME, @AREA_NAME,@STATION_NAME,@TASK_CODE);SELECT @@IDENTITY;", task);
                return result.FirstOrDefault();
            }
        }
        /// <summary>
        /// 更新停机报告
        /// </summary>
        /// <param name="shutdown">停机报告</param>
        /// <returns></returns>
        public static bool UpdateAuditTask(AUDIT_TASK task)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                int result = connection.Execute("update AUDIT_TASK set TASK_NAME=@TASK_NAME, AREA_NAME=@AREA_NAME,STATION_NAME=@STATION_NAME,TASK_CODE=@TASK_CODE where TASK_ID=@TASK_ID", task);
                if (result > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

        /// <summary>
        /// 删除巡检任务
        /// </summary>
        /// <param name="ids">要删除的id，格式id1,id2,...</param>
        /// <returns></returns>
        public static bool DeleteAuditTask(List<int> ids)
        {
            int result = 0;
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                foreach (int id in ids)
                {
                    result += connection.Execute("delete  from AUDIT_TASK where TASK_ID = @id ", new { @id = id });

                }
                if (result > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

        /// <summary>
        /// 获取巡检线路
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static IEnumerable<DBEntity.Models.AUDIT_LINE> GetAuditLine()
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<DBEntity.Models.AUDIT_LINE>("select * from AUDIT_LINE order by SEQ asc");
                return result;
            }
        }


        /// <summary>
        /// 根据TaskID获取巡检线路
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static IEnumerable<DBEntity.Models.AUDIT_LINE> GetAuditLineByTaskID(string id)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<DBEntity.Models.AUDIT_LINE>("select * from AUDIT_LINE where TASK_ID=@id order by SEQ asc", new { @id = id });
                return result;
            }
        }

        /// <summary>
        /// 根据ID获取巡检线路
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static IEnumerable<DBEntity.Models.AUDIT_LINE> GetAuditLineByID(string id)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<DBEntity.Models.AUDIT_LINE>("select * from AUDIT_LINE where ID=@id order by SEQ asc", new { @id = id });
                return result;
            }
        }


        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="line">线路</param>
        /// <returns></returns>
        public static int InsertAuditLine(AUDIT_LINE line)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<int>("insert into  AUDIT_LINE(TASK_ID, TASK_NAME, DEVICE_ID,DEVICE_NAME,SEQ,DEVICE_Status,DEVICE_TYPE_NAME) values (@TASK_ID, @TASK_NAME, @DEVICE_ID,@DEVICE_NAME,@SEQ,@DEVICE_Status,@DEVICE_TYPE_NAME);SELECT @@IDENTITY;", line);
                return result.FirstOrDefault();
            }
        }
        /// <summary>
        /// 更新线路
        /// </summary>
        /// <param name="shutdown">线路</param>
        /// <returns></returns>
        public static bool UpdateAuditLine(AUDIT_LINE line)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                int result = connection.Execute("update AUDIT_LINE set  TASK_ID=@TASK_ID,TASK_NAME=@TASK_NAME, DEVICE_ID=@DEVICE_ID,DEVICE_ID=@DEVICE_ID where ID=@ID", line);
                if (result > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="line">线路</param>
        /// <returns></returns>
        public static bool InsertAuditLine(List<AUDIT_LINE> lines)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                //foreach (AUDIT_LINE line in lines)
                //{
                int result = connection.Execute("insert into  AUDIT_LINE(TASK_ID, TASK_NAME, DEVICE_ID,DEVICE_NAME,SEQ,DEVICE_Status,DEVICE_TYPE_NAME) values (@TASK_ID, @TASK_NAME, @DEVICE_ID,@DEVICE_NAME,@SEQ,@DEVICE_Status,@DEVICE_TYPE_NAME);", lines);
                if (result > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
                //}
            }
        }
        /// <summary>
        /// 更新线路
        /// </summary>
        /// <param name="shutdown">线路</param>
        /// <returns></returns>
        public static bool UpdateAuditLine(List<AUDIT_LINE> lines)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                int result = connection.Execute("update AUDIT_LINE set  TASK_ID=@TASK_ID,TASK_NAME=@TASK_NAME, DEVICE_ID=@DEVICE_ID,DEVICE_ID=@DEVICE_ID where ID=@ID", lines);
                if (result > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

        /// <summary>
        /// 删除巡检线路
        /// </summary>
        /// <param name="ids">要删除的id，格式id1,id2,...</param>
        /// <returns></returns>
        public static bool DeleteAuditLine(List<int> ids)
        {
            int result = 0;
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                foreach (int id in ids)
                {
                    result += connection.Execute("delete  from AUDIT_LINE where ID = @id ", new { @id = id });

                }
                if (result > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

        /// <summary>
        /// 根据DeviceID获取巡检项目
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static IEnumerable<DBEntity.Models.AUDIT_ITEMS> GetAuditItem()
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<DBEntity.Models.AUDIT_ITEMS>("select * from AUDIT_ITEMS ");
                return result;
            }
        }

        /// <summary>
        /// 根据DeviceID获取巡检项目
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static IEnumerable<DBEntity.Models.AUDIT_ITEMS> GetAuditItemByID(string id)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<DBEntity.Models.AUDIT_ITEMS>("select * from AUDIT_ITEMS where ID=@id  ", new { @id = id });
                return result;
            }
        }

        /// <summary>
        /// 根据DeviceID获取巡检项目
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static IEnumerable<DBEntity.Models.AUDIT_ITEMS> GetAuditItemByDeviceID(string id)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<DBEntity.Models.AUDIT_ITEMS>("select * from AUDIT_ITEMS where DEVICE_ID=@id  ", new { @id = id });
                return result;
            }
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="line">巡检项目</param>
        /// <returns></returns>
        public static int InsertAuditItem(AUDIT_ITEMS item)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<int>("insert into  AUDIT_ITEMS(DEVICE_ID, DEVICE_NAME, ITEMS,STANDARD,PERMISSION,PERMISSION_STATION) values (@DEVICE_ID, @DEVICE_NAME, @ITEMS,@STANDARD,@PERMISSION,@PERMISSION_STATION);SELECT @@IDENTITY;", item);
                return result.FirstOrDefault();
            }
        }

        /// <summary>
        /// 更新巡检项目
        /// </summary>
        /// <param name="items">巡检项目</param>
        /// <returns></returns>
        public static bool UpdateAuditItem(AUDIT_ITEMS items)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                int result = connection.Execute("update AUDIT_ITEMS set  DEVICE_ID=@DEVICE_ID,DEVICE_NAME=@DEVICE_NAME, ITEMS=@ITEMS,STANDARD=@STANDARD,PERMISSION=@PERMISSION,PERMISSION_STATION=@PERMISSION_STATION where ID=@ID", items);
                if (result > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

        /// <summary>
        /// 删除巡检线路
        /// </summary>
        /// <param name="ids">要删除的id，格式id1,id2,...</param>
        /// <returns></returns>
        public static bool DeleteAuditItem(List<int> ids)
        {
            int result = 0;
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                foreach (int id in ids)
                {
                    result += connection.Execute("delete  from AUDIT_ITEMS where ID = @id ", new { @id = id });

                }
                if (result > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

        /// <summary>
        /// 根据DeviceID获取DeviceType
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static IEnumerable<DBEntity.Models.AUDIT_DEVICE> GetAuditDeviceByDeviceID(string id)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<DBEntity.Models.AUDIT_DEVICE>("select * from AUDIT_DEVICE where DEVICE_ID=@id  ", new { @id = id });
                return result;
            }
        }

        /// <summary>
        /// 根据DeviceID获取DeviceType
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static IEnumerable<DBEntity.Models.AUDIT_DEVICE> GetAuditDevice( string area)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                if (string.IsNullOrEmpty(area))
                {
                    var result = connection.Query<DBEntity.Models.AUDIT_DEVICE>("select * from AUDIT_DEVICE ");
                    return result;
                }
                else
                {
                    var result = connection.Query<DBEntity.Models.AUDIT_DEVICE>("select * from AUDIT_DEVICE where AREA_NAME =@area", new { @area = area });
                    return result;
                }
            }
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="line">巡检点</param>
        /// <returns></returns>
        public static DBEntity.Models.AUDIT_DEVICE InsertAuditDevice(AUDIT_DEVICE device)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<AUDIT_DEVICE>("insert into  AUDIT_DEVICE(DEVICE_ID, DEVICE_NAME, DEVICE_TYPE_NAME,AREA_NAME,DEVICE_CODE) values (@DEVICE_ID, @DEVICE_NAME, @DEVICE_TYPE_NAME,@AREA_NAME,@DEVICE_CODE);SELECT *  from AUDIT_DEVICE where DEVICE_ID=@DEVICE_ID;", device);
                return result.FirstOrDefault();
            }
        }

        /// <summary>
        /// 更新巡检项目
        /// </summary>
        /// <param name="period">巡检项目</param>
        /// <returns></returns>
        public static bool UpdateAuditDevice(AUDIT_DEVICE device)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                int result = connection.Execute("update AUDIT_DEVICE set DEVICE_NAME=@DEVICE_NAME, DEVICE_TYPE_NAME=@DEVICE_TYPE_NAME,AREA_NAME=@AREA_NAME,DEVICE_CODE=@DEVICE_CODE where DEVICE_ID=@DEVICE_ID", device);
                if (result > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

        /// <summary>
        /// 删除巡检点
        /// </summary>
        /// <param name="ids">要删除的id，格式id1,id2,...</param>
        /// <returns></returns>
        public static bool DeleteAuditDevice(List<int> ids)
        {
            int result = 0;
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                foreach (int id in ids)
                {
                    result += connection.Execute("delete  from AUDIT_DEVICE where DEVICE_ID = @id;delete from AUDIT_ITEMS where DEVICE_ID = @id;", new { @id = id });

                }
                if (result > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

        /// <summary>
        /// 根据DeviceID获取DeviceType
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static IEnumerable<DBEntity.Models.AUDIT_STATION> GetAuditStation()
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<DBEntity.Models.AUDIT_STATION>("select * from AUDIT_STATION  where STATION_ID<>0");               
                return result;
            }
        }

        /// <summary>
        /// 获取区域
        /// </summary>       
        /// <returns></returns>
        public static IEnumerable<DBEntity.Models.AUDIT_AREA> GetAuditArea()
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<DBEntity.Models.AUDIT_AREA>("select * from AUDIT_AREA ");
                return result;
            }
        }

        /// <summary>
        /// 获取区域
        /// </summary>       
        /// <returns></returns>
        public static IEnumerable<DBEntity.Models.AUDIT_DEVICE_TYPE> GetAuditDeviceType()
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<DBEntity.Models.AUDIT_DEVICE_TYPE>("select * from AUDIT_DEVICE_TYPE ");
                return result;
            }
        }


        /// <summary>
        /// 获取巡检计划执行结果
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<DBEntity.Models.AUDIT_PLAN> GetAuditPlan(string area,string stime,string etime,string status)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<DBEntity.Models.AUDIT_PLAN>("select * from AUDIT_PLAN where AREA_NAME = @area "
                    , new { @area = area });
                if (!string.IsNullOrEmpty(stime))
                {
                    result = result.Where(t => t.S_TIME >=DateTime.Parse(stime));
                }
                if (!string.IsNullOrEmpty(etime))
                {
                    result = result.Where(t => t.E_TIME <=  DateTime.Parse(etime).AddDays(1));
                }
                if (!string.IsNullOrEmpty(status))
                {
                    result = result.Where(t => t.status == status );
                }
                return result.ToList();//tolist避免调用方绑定空行
            }
        }

        /// <summary>
        /// 获取巡检计划点位巡检结果
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<DBEntity.Models.AUDIT_WORKLOG> GetAuditPlanDevice(string planId)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<DBEntity.Models.AUDIT_WORKLOG>("select * from AUDIT_WORKLOG where PLANID = @planId"
                    , new { @planId = planId });
                return result;
            }
        }

        /// <summary>
        /// 获取巡检计划巡检项巡检结果
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<DBEntity.Models.AUDIT_WORKLOG_ITEMS> GetAuditPlanItem(string planId,string deviceId)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<DBEntity.Models.AUDIT_WORKLOG_ITEMS>("select * from AUDIT_WORKLOG_ITEMS where PLANID = @planId and DEVICE_ID=@deviceId"
                    , new { @planId = planId, @deviceId = deviceId });
                return result;
            }
        }

        /// <summary>
        /// 获取巡检周期
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<DBEntity.Models.AUDIT_PERIOD_SET> GetAuditPeriod(string id)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<DBEntity.Models.AUDIT_PERIOD_SET>("select * from AUDIT_PERIOD_SET where ID = @id "
                  , new { @id = id });         
                return result;
            }
        }

        /// <summary>
        /// 获取巡检周期
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<DBEntity.Models.AUDIT_PERIOD_SET> GetAuditPeriod(string area, string taskId)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<DBEntity.Models.AUDIT_PERIOD_SET>("select * from AUDIT_PERIOD_SET where AREA_NAME = @area "
                  , new { @area = area });
                if (!string.IsNullOrEmpty(taskId))
                {
                    result = result.Where(t => t.TASK_ID == Int32.Parse(taskId));
                }
                return result;
            }
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="line">巡检点</param>
        /// <returns></returns>
        public static DBEntity.Models.AUDIT_PERIOD_SET InsertAuditPeriod(AUDIT_PERIOD_SET period)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var result = connection.Query<AUDIT_PERIOD_SET>("insert into  AUDIT_PERIOD_SET(AREA_NAME, TASK_ID, TASK_NAME,SHIFT,BASE_DATE,START_TIME,END_TIME,TYPE,PERIOD_TIME,CLASS_SET,ENABLE,HOLIDAY,REMARK) values (@AREA_NAME, @TASK_ID, @TASK_NAME,@SHIFT,@BASE_DATE,@START_TIME,@END_TIME,@TYPE,@PERIOD_TIME,@CLASS_SET,@ENABLE,@HOLIDAY,@REMARK);select @@IDENTITY;", period);
                return result.FirstOrDefault();
            }
        }

        /// <summary>
        /// 更新巡检周期
        /// </summary>
        /// <param name="period">巡检周期</param>
        /// <returns></returns>
        public static bool UpdateAuditPeriod(AUDIT_PERIOD_SET period)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                int result = connection.Execute(@"update AUDIT_PERIOD_SET set AREA_NAME=@AREA_NAME, TASK_ID=@TASK_ID,TASK_NAME=@TASK_NAME,SHIFT=@SHIFT,
                                                    BASE_DATE=@BASE_DATE, START_TIME=@START_TIME,END_TIME=@END_TIME,TYPE=@TYPE,
                                                    PERIOD_TIME=@PERIOD_TIME, CLASS_SET=@CLASS_SET,ENABLE=@ENABLE,HOLIDAY=@HOLIDAY,REMARK=@REMARK
                                            where ID=@ID", period);
                if (result > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

        /// <summary>
        /// 删除巡检周期
        /// </summary>
        /// <param name="ids">要删除的id，格式id1,id2,...</param>
        /// <returns></returns>
        public static bool DeleteAuditPeriod(List<int> ids)
        {
            int result = 0;
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                foreach (int id in ids)
                {
                    result += connection.Execute("delete  from AUDIT_PERIOD_SET where ID = @id;", new { @id = id });

                }
                if (result > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

        #endregion

    }
}

